<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="500px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="客户基本信息导入ID" >
        <el-input v-model="form.custId" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="合同编号" >
        <el-input v-model="form.contractNo" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="借据标号" >
        <el-input v-model="form.evidenceNo" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款起始日" >
        <el-input v-model="form.startDate" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款终止日" >
        <el-input v-model="form.endDate" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款期限（月）" >
        <el-input v-model="form.loanPeriod" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款形式" >
        <el-input v-model="form.loanForm" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="还款方式" >
        <el-input v-model="form.repayMethod" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="授信品种" >
        <el-input v-model="form.creditKind" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款总额（万元）" >
        <el-input v-model="form.loanQuota" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="正常贷款余额（万元）" >
        <el-input v-model="form.normalLoanBalance" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="逾期贷款余额（万元）" >
        <el-input v-model="form.overdueLoanBalance" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="七级分类" >
        <el-input v-model="form.sevenType" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="展期次数" >
        <el-input v-model="form.expoTimes" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="展期终止日期" >
        <el-input v-model="form.expoEndDate" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="币种" >
        <el-input v-model="form.currencyType" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款后投向行业门类" >
        <el-input v-model="form.loanIndustryType" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款后投向行业门类大类" >
        <el-input v-model="form.loanIndustryTypeL" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款后投向行业门类中类" >
        <el-input v-model="form.loanIndustryTypeM" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款后投向行业门类小类" >
        <el-input v-model="form.loanIndustryTypeS" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款产品名称（二级）" >
        <el-input v-model="form.loanProdName2" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="核心会计科目" >
        <el-input v-model="form.accountingSubject" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="核心会计科目号" >
        <el-input v-model="form.accountingSubjectNo" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信贷产品代码（三级）" >
        <el-input v-model="form.creditProdCode" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信贷产品名称（三级）" >
        <el-input v-model="form.creditProdName3" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="总授信额度" >
        <el-input v-model="form.creditQuota" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="本金逾期天数" >
        <el-input v-model="form.principalOverdueDays" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="利息逾期天数" >
        <el-input v-model="form.ratesOverdueDays" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="利率调整模式" >
        <el-input v-model="form.ratesSetMode" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="利率" >
        <el-input v-model="form.rates" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="利率浮动值" >
        <el-input v-model="form.ratesChangeVal" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="主要担保方式" >
        <el-input v-model="form.mainVouchMethod" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="担保明细（二级）" >
        <el-input v-model="form.vouchDetails2" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="担保明细（三级）" >
        <el-input v-model="form.vouchDetails3" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="非应记贷款余额（万元）" >
        <el-input v-model="form.loanBalance" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款账号" >
        <el-input v-model="form.loanAccount" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="是否融资平台贷款" >
        <el-input v-model="form.isFinancingPlat" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="用途" >
        <el-input v-model="form.useDirect" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信用等级" >
        <el-input v-model="form.creditLevel" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="贷款合同金额（万元）" >
        <el-input v-model="form.contractQuota" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="是否绿色信贷" >
        <el-input v-model="form.isGreenCredit" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="绿色信贷用途" >
        <el-input v-model="form.greenUseDirect" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="按用途划分的有关行业贷款" >
        <el-input v-model="form.industryLoan" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="导入日期" >
        <el-input v-model="form.importDate" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="是否环境、安全等重大风险企业贷款" >
        <el-input v-model="form.isRiskLoan" style="width: 370px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { add, edit } from '@/api/custComLoanInfo'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        custId: '',
        contractNo: '',
        evidenceNo: '',
        startDate: '',
        endDate: '',
        loanPeriod: '',
        loanForm: '',
        repayMethod: '',
        creditKind: '',
        loanQuota: '',
        normalLoanBalance: '',
        overdueLoanBalance: '',
        sevenType: '',
        expoTimes: '',
        expoEndDate: '',
        currencyType: '',
        loanIndustryType: '',
        loanIndustryTypeL: '',
        loanIndustryTypeM: '',
        loanIndustryTypeS: '',
        loanProdName2: '',
        accountingSubject: '',
        accountingSubjectNo: '',
        creditProdCode: '',
        creditProdName3: '',
        creditQuota: '',
        principalOverdueDays: '',
        ratesOverdueDays: '',
        ratesSetMode: '',
        rates: '',
        ratesChangeVal: '',
        mainVouchMethod: '',
        vouchDetails2: '',
        vouchDetails3: '',
        loanBalance: '',
        loanAccount: '',
        isFinancingPlat: '',
        useDirect: '',
        creditLevel: '',
        contractQuota: '',
        isGreenCredit: '',
        greenUseDirect: '',
        industryLoan: '',
        importDate: '',
        isRiskLoan: ''
      },
      rules: {
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      this.loading = true
      if (this.isAdd) {
        this.doAdd()
      } else this.doEdit()
    },
    doAdd() {
      add(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    doEdit() {
      edit(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: '',
        custId: '',
        contractNo: '',
        evidenceNo: '',
        startDate: '',
        endDate: '',
        loanPeriod: '',
        loanForm: '',
        repayMethod: '',
        creditKind: '',
        loanQuota: '',
        normalLoanBalance: '',
        overdueLoanBalance: '',
        sevenType: '',
        expoTimes: '',
        expoEndDate: '',
        currencyType: '',
        loanIndustryType: '',
        loanIndustryTypeL: '',
        loanIndustryTypeM: '',
        loanIndustryTypeS: '',
        loanProdName2: '',
        accountingSubject: '',
        accountingSubjectNo: '',
        creditProdCode: '',
        creditProdName3: '',
        creditQuota: '',
        principalOverdueDays: '',
        ratesOverdueDays: '',
        ratesSetMode: '',
        rates: '',
        ratesChangeVal: '',
        mainVouchMethod: '',
        vouchDetails2: '',
        vouchDetails3: '',
        loanBalance: '',
        loanAccount: '',
        isFinancingPlat: '',
        useDirect: '',
        creditLevel: '',
        contractQuota: '',
        isGreenCredit: '',
        greenUseDirect: '',
        industryLoan: '',
        importDate: '',
        isRiskLoan: ''
      }
    }
  }
}
</script>

<style scoped>

</style>
